home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / pressgen / an311x.exe / INSTALL.C < prev    next >
C/C++ Source or Header  |  1993-10-15  |  5KB  |  164 lines

  1. /*
  2.  ████████████████████████████████████████████████████████████████████████████
  3.  █                                                                          █
  4.  █ install.c                                                                █
  5.  █                                                                          █
  6.  █ Creates a job server and job queue to process DOS commands submitted by  █
  7.  █ submit.exe                                                               █
  8.  ████████████████████████████████████████████████████████████████████████████
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include <dos.h>
  16. #include <dir.h>
  17. #include <nwcalls.h>
  18. #include "..\doit.h"
  19.  
  20. #define NWDOS
  21.  
  22. NWCCODE        cCode;
  23. struct ffblk    ffblk;
  24. int        found;
  25. DWORD        queueID,
  26.         serverID;
  27. NWFILE_HANDLE    fileHandle;
  28. NWCONN_HANDLE    connID;
  29. NWCONN_NUM    connNumber;
  30. char NWFAR    userName[48];
  31. char        response;
  32. NWFLAGS NWFAR    installed;
  33. NWSEGMENT_DATA    segment;
  34.  
  35. void main()
  36. {
  37.     found = findfirst(JOBSERV_PATH, &ffblk, FA_DIREC);
  38.     if (found != 0) {
  39.         printf("You must create the queue directory\n");
  40.         printf("%s before installing the job server.\n", JOBSERV_PATH);
  41.         exit(-1);
  42.     }
  43.  
  44.     cCode = NWCallsInit(NULL, NULL);
  45.     if (cCode != 0) {
  46.         printf("Unable to initialize NetWare interface\n");
  47.         exit(-1);
  48.     }
  49.  
  50.     /* get the connection ID of the server you're installing on */
  51.     cCode = NWGetDefaultConnectionID(&connID);
  52.     if (cCode != 0) {
  53.         printf("Unable to get connection ID of default server\n");
  54.         exit(-1);
  55.     }
  56.  
  57.     /* create job server object */
  58.     cCode = NWCreateObject(connID, JOBSERV_NAME, OT_DOIT, BF_STATIC, BS_LOGGED_READ | BS_OBJECT_WRITE);
  59.     if (cCode == 0)
  60.         printf("Created job server bindery object\n");
  61.     else {
  62.         switch (cCode) {
  63.             case 0x89EE :    printf("Job server bindery object already created on default server\n");
  64.                     response = ' ';
  65.                     do {
  66.                         printf("Continue anyway?  (y/n)");
  67.                         response = toupper(getche());
  68.                         printf("\n");
  69.                     } while ((response !=  'Y') && (response  !=  'N'));
  70.                     if (response == 'N')
  71.                         exit(-1);
  72.                     break;
  73.             case 0x89F5 :    printf("You must be supervisor or supervisor-equivalent to install job server\n");
  74.                     exit(-1);
  75.                     break;
  76.             default :    printf("Call to NWCreateObject failed\n");
  77.                     exit(-1);
  78.                     break;
  79.         }
  80.     }
  81.  
  82.     /* create a password for the job server */
  83.     cCode = NWChangeObjectPassword(connID, JOBSERV_NAME, OT_DOIT, "", JOBSERV_PWORD);
  84.     if (cCode == 0)
  85.         printf("Set job server password\n");
  86.     else {
  87.         printf("Call to NWChangeObjectPassword failed, cCode = %X\n", cCode);
  88.         exit(-1);
  89.     }
  90.  
  91.     /* see if accounting is installed; if so, create account balance property */
  92.     cCode = NWQueryAccountingInstalled(connID, &installed);
  93.     if (installed == 1) {
  94.         cCode = NWCreateProperty(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", BF_ITEM | BF_STATIC, BS_OBJECT_READ | BS_SUPER_WRITE);
  95.         if (cCode != SUCCESSFUL) {
  96.             printf("Unable to create Account Balance property for job server object\n");
  97.             exit(-1);
  98.         }
  99.  
  100.         /* set account balance to allow unlimited credit */
  101.         segment = (NWSEGMENT_DATA)calloc(128, sizeof(BYTE));
  102.         segment[4] = 0x80;
  103.         cCode = NWWritePropertyValue(connID, JOBSERV_NAME, OT_DOIT, "ACCOUNT_BALANCE", 1, segment, 0);
  104.         if (cCode != SUCCESSFUL) {
  105.             printf("Unable to set account balance for job server object\n");
  106.             exit(-1);
  107.         }
  108.     }
  109.  
  110.     /* create a job queue */
  111.     cCode = NWCreateQueue(connID, JOBSERV_NAME, OT_DOIT_Q, 0, JOBSERV_PATH, &queueID);
  112.     if (cCode == 0)
  113.         printf("Created job queue\n");
  114.     else {
  115.         printf("Call to NWCreateQueue failed, cCode = %X\n", cCode);
  116.         if ((cCode == 0x8998) || (cCode == 0x899C))
  117.             printf("Invalid queue directory path\n");
  118.             exit(-1);
  119.     }
  120.  
  121.     /* get your connection number */
  122.     cCode = NWGetConnectionNumber(connID, &connNumber);
  123.     if (cCode != 0) {
  124.         printf("Unable to get your connection number to default server\n");
  125.         exit(-1);
  126.     }
  127.  
  128.     /* get your user name */
  129.     cCode = NWGetConnectionInformation(connID, connNumber, userName, NULL, NULL, NULL);
  130.     if (cCode != 0) {
  131.         printf("Unable to get your user name\n");
  132.         exit(-1);
  133.     }
  134.  
  135.     /* add your user to the set of queue users */
  136.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_USERS", userName, OT_USER);
  137.     if (cCode == 0)
  138.         printf("Added your object to queue users set\n");
  139.     else {
  140.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  141.         exit(-1);
  142.     }
  143.  
  144.     /* add your user to the set of queue operators */
  145.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_OPERATORS", userName, OT_USER);
  146.     if (cCode == 0)
  147.         printf("Added your object to queue operators set\n");
  148.     else {
  149.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  150.         exit(-1);
  151.     }
  152.  
  153.     /* add your new server to the set of queue servers */
  154.     cCode = NWAddObjectToSet(connID, JOBSERV_NAME, OT_DOIT_Q, "Q_SERVERS", JOBSERV_NAME, OT_DOIT);
  155.     if (cCode == 0)
  156.         printf("Added job server to queue servers set\n");
  157.     else {
  158.         printf("Call to NWAddObjectToSet failed, cCode = %X\n", cCode);
  159.         exit(-1);
  160.     }
  161.  
  162.     printf("Job server installed\n");
  163. }
  164.